package com.hxzy.springbootes.es.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.hxzy.springbootes.mybatis.entity.TbHotel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;

/**
 * @Author gityyge
 * @Description TODO
 * @Date 2023/5/31 15:43
 * @Version 1.0
 * PUT /test_hotel
 * {
 *   "mappings": {
 *     "properties": {
 *       "id": {
 *         "type": "keyword"
 *       },
 *       "name":{
 *         "type": "text",
 *         "analyzer": "ik_max_word",
 *         "copy_to": "all"
 *       },
 *       "address":{
 *         "type": "keyword",
 *         "index": false
 *       },
 *       "price":{
 *         "type": "integer"
 *       },
 *       "score":{
 *         "type": "integer"
 *       },
 *       "brand":{
 *         "type": "keyword",
 *         "copy_to": "all"
 *       },
 *       "city":{
 *         "type": "keyword",
 *         "copy_to": "all"
 *       },
 *       "starName":{
 *         "type": "keyword"
 *       },
 *       "business":{
 *         "type": "keyword"
 *       },
 *       "location":{
 *         "type": "geo_point"
 *       },
 *       "pic":{
 *         "type": "keyword",
 *         "index": false
 *       },
 *       "all":{
 *         "type": "text",
 *         "analyzer": "ik_max_word"
 *       }
 *     }
 *   }
 * }
 */
@Getter
@Setter
//indexName=索引库名,createIndex=false不要自动创建索引库
@Document(indexName = "test_hotel",createIndex = false)
public class EsHotel implements Serializable {

    /**
     * 索引主键
     */
    @Id
    private Long id;

    @Field(name = "name",type = FieldType.Text,analyzer = "ik_max_word")
    private String name;

    @Field(name = "address",type = FieldType.Keyword,index = false)
    private String address;

    @Field(name = "price",type = FieldType.Integer)
    private Integer price;

    @Field(name = "score",type = FieldType.Integer)
    private Integer score;

    @Field(name = "brand",type = FieldType.Keyword)
    private String brand;

    @Field(name = "city",type = FieldType.Keyword)
    private String city;

    @Field(name = "starName",type = FieldType.Keyword)
    private String starName;

    @Field(name = "business",type = FieldType.Keyword)
    private String business;

    /**
     *  经纬度
     *  1. 字符串
     *    `位置：lat + "," + lon`
     * 2. 数组
     *    `位置: {"lat": ...,"lon": ...}`
     * 3. 对象
     *    `位置: [lon, lat]`
     */
    private String location;

    @Field(name = "pic",type = FieldType.Keyword,index = false)
    private String pic;

    public EsHotel() {
    }

    /**
     * mysql数据库值
     * @param hotel
     */
    public EsHotel(TbHotel hotel){
        this.id = hotel.getId();
        this.name = hotel.getName();
        this.address = hotel.getAddress();
        this.price = hotel.getPrice();
        this.score = hotel.getScore();
        this.brand = hotel.getBrand();
        this.city = hotel.getCity();
        this.starName = hotel.getStarName();
        this.business = hotel.getBusiness();
        this.location = hotel.getLatitude() + ", " + hotel.getLongitude();
        this.pic = hotel.getPic();
    }


}
